/**
 * created by 小卷毛, 2020/10/14
 * Copyright (c) 2020, 416143467@qq.com All Rights Reserved.
 * #                   *********                            #
 * #                  ************                          #
 * #                  *************                         #
 * #                 **  ***********                        #
 * #                ***  ****** *****                       #
 * #                *** *******   ****                      #
 * #               ***  ********** ****                     #
 * #              ****  *********** ****                    #
 * #            *****   ***********  *****                  #
 * #           ******   *** ********   *****                #
 * #           *****   ***   ********   ******              #
 * #          ******   ***  ***********   ******            #
 * #         ******   **** **************  ******           #
 * #        *******  ********************* *******          #
 * #        *******  ******************************         #
 * #       *******  ****** ***************** *******        #
 * #       *******  ****** ****** *********   ******        #
 * #       *******    **  ******   ******     ******        #
 * #       *******        ******    *****     *****         #
 * #        ******        *****     *****     ****          #
 * #         *****        ****      *****     ***           #
 * #          *****       ***        ***      *             #
 * #            **       ****        ****                   #
 */
package com.sgcc.pda.frme.protocol.ws.sendbean;

import android.text.TextUtils;

import com.sgcc.pda.frme.protocol.ws.DataConvert;

/**
 * 描 述：
 * 作 者：小卷毛  2020-10-14 18:47
 * 修改描述：
 * 修 改 人：
 * 修改版本：
 */
public class SafeSendParams {

    /**
     * 工单编号
     */
    private String appNo;
    /**
     * 任务类型编码
     */
    private String workType;
    /**
     * 工单类型
     */
    private String appType;
    /**
     * 建立时间
     */
    private String createDate;

    public String getAppNo() {
        return appNo;
    }

    public void setAppNo(String appNo) {
        this.appNo = appNo;
    }

    public String getWorkType() {
        return workType;
    }

    public void setWorkType(String workType) {
        this.workType = workType;
    }

    public String getAppType() {
        return appType;
    }

    public void setAppType(String appType) {
        this.appType = appType;
    }

    public String getCreateDate() {
        return createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();

        if (!TextUtils.isEmpty(appNo)){
            String num1 = strTo16(appNo);
            if (num1.length() < 40) num1 = lengthfilling(num1, 40);
            sb.append(DataConvert.strReverse(num1, 0, num1.length()));
        }

        if (!TextUtils.isEmpty(workType)) {
            String num2 = workType;
            if (num2.length() < 4) num2 = lengthfilling(num2, 4);
            sb.append(DataConvert.strReverse(num2, 0, num2.length()));
        }

        if (!TextUtils.isEmpty(createDate)) {
            String num3 = strTo16(createDate);
            if (num3.length() < 28) num3 = lengthfilling(num3, 28);
            sb.append(DataConvert.strReverse(num3, 0, num3.length()));
        }


        if (!TextUtils.isEmpty(appType)) {
            String num4 = strTo16(string2Unicode(appType));
            sb.append(DataConvert.strReverse(num4, 0, num4.length()));
        }

        return sb.toString();
    }

    private String lengthfilling(String data, int length) {
        if (!TextUtils.isEmpty(data)
                && data.length() < length) {
            StringBuilder stringBuffer = new StringBuilder();
            for (int i = 0; i < length - data.length(); i++) {
                stringBuffer.append("0");
            }
            stringBuffer.append(data);
            data = stringBuffer.toString();
            return data;
        }
        return "";
    }

    /**
     * 字符串转化成为16进制字符串
     */
    private String strTo16(String s) {
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            int ch = s.charAt(i);
            String s4 = Integer.toHexString(ch);
            str.append(s4);
        }
        return str.toString();
    }

    /**
     * 字符串转换unicode
     */
    private String string2Unicode(String string) {
        StringBuilder unicode = new StringBuilder();
        for (int i = 0; i < string.length(); i++) {
            char c = string.charAt(i);
            unicode.append("\\u").append(Integer.toHexString(c));
        }
        return unicode.toString();
    }

}
